package com.bilicraft.plugin.kexue.commands;

import java.io.File;
import java.text.SimpleDateFormat;

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

import com.bilicraft.plugin.kexue.ShellUser;

public class BiliCmdLs extends BiliCmd{
	public BiliCmdLs(){
		nofArgs = 0;
	}
	public boolean doExec(CommandSender sender, Command cmd, String label, String[] args, ShellUser shellUser){
		try{
			File fdir = new File(shellUser.curdir);
			shellUser.curdir = fdir.getCanonicalPath();
			if(!fdir.exists()){
				sender.sendMessage("Path error.");
				return true;
			}
			SimpleDateFormat sdf= new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
			String[] files = fdir.list();
			sender.sendMessage("File in "+shellUser.curdir+":");
			for(String file:files){
				File ff = new File(shellUser.curdir, file);
				String type = ff.isDirectory()?"[D]":"[F]";
				String last = sdf.format(ff.lastModified());
				sender.sendMessage(type+"["+last+"]"+file);
			}
			return true;
		}catch(Exception e){
			e.printStackTrace();
		}
		return false;
	}
}
